﻿#region USING STATEMENTS
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
#endregion

#region CODE BODY
namespace Fusion
{
    public class Canvas : SpriteBatch
    {
        //////////////////////////////////////////////////
        // Data Fields
        //////////////////////////////////////////////////
        private Texture2D Pixel;

        //////////////////////////////////////////////////
        // Constructors
        //////////////////////////////////////////////////
        public Canvas(GraphicsDevice Device)
            : base(Device)
        {
            Pixel = new Texture2D(Device, 1, 1);
            Pixel.SetData<Color>(new Color[] { Color.White });
        }

        //////////////////////////////////////////////////
        // Methods
        //////////////////////////////////////////////////
        public void DrawRectangle(Rectangle ToDraw, Single Thickness, Color Overlay)
        {
            Vector2 TopLeft = new Vector2(ToDraw.X, ToDraw.Y);
            Vector2 TopRight = new Vector2(ToDraw.X + ToDraw.Width, ToDraw.Y);
            Vector2 BotLeft = new Vector2(ToDraw.X, ToDraw.Y + ToDraw.Height);
            Vector2 BotLeftBot = new Vector2(ToDraw.X - Thickness, ToDraw.Y + ToDraw.Height);
            Vector2 BotRight = new Vector2(ToDraw.X + ToDraw.Width, ToDraw.Y + ToDraw.Height);

            DrawLine(TopLeft, TopRight, Thickness, Overlay);
            DrawLine(BotLeftBot, BotRight, Thickness, Overlay);
            DrawLine(TopLeft, BotLeft, Thickness, Overlay);
            DrawLine(TopRight, BotRight, Thickness, Overlay);
        }
        public void FillRectangle(Rectangle ToFill, Color Overlay)
        {
            Draw(Pixel, ToFill, Overlay);
        }
        public void DrawLine(Vector2 PointOne, Vector2 PointTwo, Single Thickness, Color Overlay)
        {
            Single Angle = (Single)Math.Atan2(PointTwo.Y - PointOne.Y, PointTwo.X - PointOne.X);
            Single Length = Vector2.Distance(PointOne, PointTwo);

            Draw(Pixel, PointOne, null, Overlay, Angle, Vector2.Zero, new Vector2(Length, Thickness), SpriteEffects.None, 0.5f);
        }
    }
}
#endregion

//////////////////////////////////////////////////////////////////////////////////////////////
// Copyright 2012 Jeffery Thomas Sventora
//////////////////////////////////////////////////////////////////////////////////////////////
